using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tKitchen
{
    public partial class UnitInput : Form
    {
        UnitPresenter presenter;

        public UnitInput(UnitPresenter presenterIn)
        {
            InitializeComponent();
            presenter = presenterIn;

        }

        private void UnitInput_Load(object sender, EventArgs e)
        {
            
        }


        public void SetDataSource(List<Unit> unitList)
        {
            dataGridView1.DataSource = unitList;
        }


        private void buttonAdd_Click(object sender, EventArgs e)
        {
            //check for empty boxes first
            //any of them could be null, but make sure then put somehting in
            if (textBoxAbbrev.Text != "" || textBoxDescr.Text != "" || textBoxName.Text != "")
            {

                presenter.AddUnit(textBoxName.Text, textBoxAbbrev.Text, textBoxDescr.Text);
                textBoxName.Clear();
                textBoxAbbrev.Clear();
                textBoxDescr.Clear();
                textBoxName.Focus();
            }
        }



        internal void RefreshGrid()
        {
            dataGridView1.Refresh();
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            List<Unit> unitList = (List<Unit>)dataGridView1.DataSource;
            Unit tempUnit = unitList[e.RowIndex];
            presenter.UpdateUnit(tempUnit);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}